<?php

class HTML_ALink extends HTML implements HTMLElements {
	private $attributeHref;
	private $attributeOnClick;
	
	const HTML_ALINK = 'a';
	const ATTRIBUTE_HREF = 'href';
	const ATTRIBUTE_ONCLICK = 'onclick';
	
	/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 *  - $href
	 *  - $onclick
	 * @param unknown_type $parent
	 * @param unknown_type $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeHref ($href)  {
		$this->attributeHref = $href;
	}
	
	public function setAttributeOnClick ($onClick)  {
		$this->attributeOnClick = $onClick;
	}
	
	public function getAttributeHref ()  {
		return $this->attributeHref;
	}
	
	public function getAttributeOnClick ()  {
		return $this->attributeOnClick;
	}
	
	public function getALinkAttributes ()  {
		
		$output = '';
		
		if (!empty($this->attributeHref))  {
			$output .= ' '. self::ATTRIBUTE_HREF. '="'. $this->getAttributeHref(). '"';
		}
		if (!empty($this->attributeOnClick))  {
			$output .= ' '. self::ATTRIBUTE_ONCLICK. '="'. $this->getAttributeOnClick(). '"';
		}
		
		if ($output == '')  {
			$output = ' ';
		}
		
		return $output;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_HREF;
		$attributes[] = self::ATTRIBUTE_ONCLICK;
		
		return array_merge($parentAttributes, $attributes);
		
	}
	
	public function toString ()  {
		
		$output = '<'. self::HTML_ALINK.
					$this->getHTMLAttributes().
					$this->getALinkAttributes(). '>';
		
		if ($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
					
		$output .= '</'. self::HTML_ALINK. '>';
		
		return $output;
	}
	
	
}
?>